package jp.sourceforge.akjrcp.videotools.wizards;

import jp.sourceforge.akjrcp.akj_betas.Messages;
import jp.sourceforge.akjrcp.commons.ui.FileDirChoicer;
import jp.sourceforge.akjrcp.commons.ui.AbstractFileDirChoicer.FileStatusChangeEvent;
import jp.sourceforge.akjrcp.commons.ui.AbstractFileDirChoicer.FileStatusChangeListener;
import jp.sourceforge.akjrcp.commons.ui.widget.WidgetBuilder;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

public class FileSelectPage extends WizardPage{


	private String inputFilePath="";
	private String outputDirPath="";
	protected FileSelectPage(String pageName) {
		super(pageName);
		setTitle(Messages.getString("videotools.wizard_videotoimage_fileselect_title"));
		
		setDescription(Messages.getString("videotools.wizard_videotoimage_fileselect_title_description"));
		
	}

	public void createControl(Composite parent) {
		Composite composite=new Composite(parent,SWT.NULL);
		composite.setLayout(new GridLayout(1,false));
		setControl(composite);
		
		WidgetBuilder.createLabel(composite, "videotools.wizard_input_video");
		FileDirChoicer videoChoicer=new FileDirChoicer(composite,SWT.NULL,FileDirChoicer.FILE,"");
		videoChoicer.addFileListChangeListener(new FileStatusChangeListener(){

			@Override
			public void addList(FileStatusChangeEvent event) {
				inputFilePath=((FileDirChoicer)event.getSource()).getAbsoluteFilePath();
				updatePageComplete();
				
			}

			@Override
			public void removeList(FileStatusChangeEvent event) {
				inputFilePath=((FileDirChoicer)event.getSource()).getAbsoluteFilePath();
				updatePageComplete();
			}});
		
		
		WidgetBuilder.createLabel(composite, "videotools.wizard_output_dir");
		FileDirChoicer dirChoicer=new FileDirChoicer(composite,SWT.NULL,FileDirChoicer.DIR,"");
		dirChoicer.addFileListChangeListener(new FileStatusChangeListener(){

			@Override
			public void addList(FileStatusChangeEvent event) {
				outputDirPath=((FileDirChoicer)event.getSource()).getAbsoluteFilePath();
				updatePageComplete();
				
			}

			@Override
			public void removeList(FileStatusChangeEvent event) {
				outputDirPath=((FileDirChoicer)event.getSource()).getAbsoluteFilePath();
				updatePageComplete();
			}});
	}
	
	
	public void updatePageComplete(){
		setPageComplete(!inputFilePath.equals("") && !outputDirPath.equals(""));
	}
	

	
}
